package com.baobao_jk.tutorialmod.util.handlers;

import com.baobao_jk.tutorialmod.init.ModBlocks;
import com.baobao_jk.tutorialmod.init.ModEntity;
import com.baobao_jk.tutorialmod.init.ModItems;
import com.baobao_jk.tutorialmod.util.IHasModel;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityEntry;

@EventBusSubscriber
public class RegistryHandler {

    @SubscribeEvent
    public static void onItemRegister(RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(ModItems.ITEMS.toArray(new Item[0])); //添加items到ITEMS数组
    }

    @SubscribeEvent
    public static void onBlockRegister(RegistryEvent.Register<Block> event) {
        event.getRegistry().registerAll(ModBlocks.BLOCKS.toArray(new Block[0])); //添加blocks到BLOCKS数组
    }

    @SubscribeEvent
    public static void onEntityRegister(RegistryEvent.Register<EntityEntry> event) {
        event.getRegistry().registerAll(ModEntity.ENTITYS.toArray(new EntityEntry[0])); //添加blocks到BLOCKS数组
    }

    @SubscribeEvent
    public static void onModelRegister(ModelRegistryEvent event) {

        for(Item item : ModItems.ITEMS) { //for循环 注册items
            if(item instanceof IHasModel) {
                ((IHasModel)item).registerModels();
            }
        }
        for(Block block : ModBlocks.BLOCKS) { //for循环 注册blocks
            if(block instanceof IHasModel) {
                ((IHasModel)block).registerModels();
            }
        }
    }
}

